<template>
  <rx-dialog @handOk="handleSubmit" @cancel="cancel">
    <rx-layout>
      <div slot="center">
    <a-form :form="form" style="margin-top:20px;">
      <a-form-item style="display:none">
        <a-input v-decorator="['id']"/>
      </a-form-item>
      <a-row>
        <a-col :span="12">
          <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="i18n('form.name','名称')">
            <a-input :placeholder="i18n('form.name','名称')" v-decorator="['name', {rules: [{required: true, message: i18n('form.name','名称','input')}]}]"/>
          </a-form-item>
        </a-col>
        <a-col :span="12">
          <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="i18n('form.expiration','过期时长(秒)')">
            <a-input-number :min="0" :max="1000000" :placeholder="i18n('form.expirationTime','过期时间')" v-decorator="['expire', {rules: [{required: false, message: i18n('form.expirationTime','过期时间','input')}]}] "/>
          </a-form-item>
        </a-col>
      </a-row>
        <a-row v-if="pkId && pkId!=''">
            <a-col :span="24">
                <a-form-item :labelCol="labelCol1" :wrapperCol="wrapperCol1" label="AppId">
                    {{mdl.id}}
                </a-form-item>
            </a-col>
        </a-row>
      <a-row>
        <a-col :span="24">
          <a-form-item :labelCol="labelCol1" :wrapperCol="wrapperCol1" :label="i18n('form.secret','密钥')">
            <a-input :placeholder="i18n('form.secret','密钥')" v-decorator="['secret', {rules: [{required: true, message: i18n('form.secret','密钥','input')}]}]" style="width:70%"/>
            &nbsp;<a-button @click="genSecret">{{i18n('form.genSecret','生成密钥')}}</a-button>
          </a-form-item>
        </a-col>
      </a-row>
        <a-row>
            <a-col :span="24">
                <a-form-item :labelCol="labelCol1" :wrapperCol="wrapperCol1" :label="i18n('form.ipOrDomainWhite','访问白名单')">
                    <a-textarea :placeholder="i18n('msa.whiteDesc','请输入...')" v-decorator="['ipOrDomainWhite', {rules: [{required: false, message: i18n('msa.ipOrDomain','请输入IP或域名')}]}]" style="width:70%"/>
                </a-form-item>
            </a-col>
        </a-row>
        <a-row>
            <a-col :span="24">
                <a-form-item :labelCol="labelCol1" :wrapperCol="wrapperCol1" :label="i18n('form.ipOrDomainBlack','访问黑名单')">
                    <a-textarea :placeholder="i18n('msa.blackDesc','请输入...')" v-decorator="['ipOrDomainBlack', {rules: [{required: false, message: i18n('msa.ipOrDomain','请输入IP或域名')}]}]" style="width:70%"/>
                </a-form-item>
            </a-col>
        </a-row>
      <a-row>
        <a-col :span="12">
          <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="i18n('form.isLog','记录日志')">
            <a-radio-group :placeholder="i18n('form.isLog','记录日志')" v-decorator="['isLog',{initialValue:'true'}]">
              <a-radio value="true">{{i18n('form.yes','是')}}</a-radio>
              <a-radio value="false">{{i18n('form.no','否')}}</a-radio>
            </a-radio-group>
          </a-form-item>
        </a-col>
        <a-col :span="12">
          <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="i18n('form.enabled','是否启用')">
          <a-radio-group :placeholder="i18n('form.enabled','是否启用')" v-decorator="['enable',{initialValue:'true'}]">
            <a-radio value="true">{{i18n('form.yes','是')}}</a-radio>
            <a-radio value="false">{{i18n('form.no','否')}}</a-radio>
          </a-radio-group>
          </a-form-item>
        </a-col>
      </a-row>

    </a-form>
      </div>
    </rx-layout>
  </rx-dialog>
</template>
<script>
  import SysAuthManagerApi from '@/api/system/core/sysAuthManager'
  import {BaseForm,RxDialog} from "@lowcode/jpaas-common-lib";
  export default {
    name: 'SysAuthManagerEdit',
    mixins:[BaseForm],
    components: {
      RxDialog,
    },
    methods: {
      i18n(name,text,key){
          return this.$ti18(name,text,"SysAuthManager",key);
      },
      get(id){
        return SysAuthManagerApi.get(id);
      },
      save(values){
        return SysAuthManagerApi.save(values);
      },
      genSecret(){
        SysAuthManagerApi.genSecret().then(res=>{
          this.form.setFieldsValue({'secret':res});
        })
      }
    }
  }
</script>
